package cn.idu.jdbc;

import com.mysql.jdbc.Driver;

import java.sql.*;

public class JdbcDemo01 {

    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Connection connection = JdbcUtils.getConnector();
        //4. 执行sql的对象，去执行sql
        Statement statement = connection.createStatement();//执行sql的对象
        String sql = "select * from users;";
        ResultSet resultSet = statement.executeQuery(sql);
        while (resultSet.next()) {
            System.out.println("\nid=" + resultSet.getInt(1));
            System.out.println("name=" + resultSet.getString(2));
            System.out.println("password=" + resultSet.getString(3));
            System.out.println("email=" + resultSet.getString(4));
            System.out.println("birthday=" + resultSet.getString(5));

            System.out.println("id=" + resultSet.getObject("id"));
            System.out.println("name=" + resultSet.getObject("name"));
            System.out.println("password=" + resultSet.getObject("password"));
            System.out.println("email=" + resultSet.getObject("email"));
            System.out.println("birthday=" + resultSet.getObject("birthday"));
        }
        //6. 释放连接
        JdbcUtils.release(connection, statement, resultSet);
    }
}
